//
//  datePickerActionSheet.m
//  Gone
//
//  Created by xiaowuxiaowu on 15/7/2.
//  Copyright (c) 2015年 xiaowuxiaowu. All rights reserved.
//

#import "DatePickerActionSheet.h"
#import "NSDate+Tripvi.h"

@interface DatePickerActionSheet()<actionSheetDelegate>
@property (nonatomic,strong)HzxActionSheet *actionSheet;


@property (nonatomic,copy)datePickerActionSheetBlock block;
@end


@implementation DatePickerActionSheet

-(instancetype)initWithDate:(NSString *)dateString datePickerMode:(UIDatePickerMode )datePickerMode {
    if(self = [super init]){
        _actionSheet = nil;
        _actionSheet = [[HzxActionSheet alloc] init];
        _actionSheet.delegate = self;
        _datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, WidthScaleSize(300), 180)];
        _datePicker.tag = 989;
//        _datePicker.calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
        [_datePicker setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"]];
        _datePicker.date = dateString.length>0 ? [NSDate dateFromStringWithYYYYMMDDSS:dateString]:[NSDate date];
        _datePicker.datePickerMode = datePickerMode;
        
//        NSDate *nowDate = [NSDate date];
//        _datePicker.maximumDate = [NSDate dateWithString:[NSString stringWithFormat:@"%@ 15:00:00",[nowDate stringWithFormat:@"yyyy-MM-dd"]] format:kNSDateHelperFormatSQLDateWithTime];
        _datePicker.timeZone = [NSTimeZone defaultTimeZone];
        [_actionSheet showHzxActionsheetWithView:_datePicker];
      //  NSDate *date = [DatePickerActionSheet getchooseDate];
       // if(date)
         //  [_datePicker setDate:date animated:YES];
    }
    return self;
}
-(void)showBlock:(datePickerActionSheetBlock)block{
        self.block = block;
}
#pragma mark myactionsheet delegate  //获取时间
-(void)commitAction:(HzxActionSheet *)sheet withMyView:(UIView *)myView{

    self.block([[_datePicker date] stringFromDateWithFormat:kNSDateHelperFormatSQLDateWithTimeYYYYMMDDHHmmss],[_datePicker date]);
    [DatePickerActionSheet setchooseDate:[_datePicker date]];
}

static const char kDateKey = '\0';
+(void)setchooseDate:(NSDate *)date{
    
    objc_setAssociatedObject(self, &kDateKey, date, OBJC_ASSOCIATION_RETAIN);
  
}
+(NSDate *)getchooseDate{
  
    return objc_getAssociatedObject(self, &kDateKey);
}
@end
